<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('membership_model');
	}

	function index()
	{	$data['main_content']='login_view';
		$data['title']='Login';
		$this->load->view('login_page',$data);	
	}
	function verifylogin()
	{    
		$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
		$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
	        if ($this->form_validation->run())
		{
			$result = $this->membership_model->validate();
			if($result) // if the user's credentials validated...
			{
				$row=$result->row();
				$data = array(
					'username' => $this->input->post('username'),
					'type'=> $row->type,
					 'logged_in' => true
				 );
				$this->session->set_userdata($data);
				$page=$this->input->post('redirect');
				redirect($page,'refresh');
			}
		}
		/* validation failed*/
		$data['main_content']='login_view';
		$data['title']='Login';
		$this->load->view('login_page',$data);
	}
}

?>